core: Add OSTREE_OBJECT_TYPE_COMMIT_META
authorMathnerd314 <mathnerd314.gph+hs@gmail.com>
Thu, 16 Jun 2016 05:37:29 +0000 (23:37 -0600)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 22 Jun 2016 16:10:01 +0000 (16:10 +0000)
This is cleaner than the loose_path_with_suffix approach

Closes: #359
Approved by: cgwalters

src/libostree/ostree-core-private.h
src/libostree/ostree-core.c
src/libostree/ostree-core.h
src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.c

index 91d52f1bd309a0289fd5361a6a94a690166d1731..b49e5e4715c91c17265dcc0c3500e79d85233554 100644 (file)
@@ -128,13 +128,6 @@ _ostree_loose_path (char              *buf,
                     OstreeObjectType   objtype,
                     OstreeRepoMode     repo_mode);
 
-void
-_ostree_loose_path_with_suffix (char              *buf,
-                                const char        *checksum,
-                                OstreeObjectType   objtype,
-                                OstreeRepoMode     repo_mode,
-                                const char        *suffix);
-
 #define _OSTREE_METADATA_GPGSIGS_NAME "ostree.gpgsigs"
 #define _OSTREE_METADATA_GPGSIGS_TYPE G_VARIANT_TYPE ("aay")
 
index 4e3816f5197a4d73e85fa35c8f4efff4d05ef859..32f0fd449ea4d8837f929b211a10545b28b1fcc9 100644 (file)
@@ -1047,6 +1047,8 @@ ostree_object_type_to_string (OstreeObjectType objtype)
       return "commit";
     case OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT:
       return "tombstone-commit";
+    case OSTREE_OBJECT_TYPE_COMMIT_META:
+      return "commitmeta";
     default:
       g_assert_not_reached ();
       return NULL;
@@ -1070,6 +1072,10 @@ ostree_object_type_from_string (const char *str)
     return OSTREE_OBJECT_TYPE_DIR_META;
   else if (!strcmp (str, "commit"))
     return OSTREE_OBJECT_TYPE_COMMIT;
+  else if (!strcmp (str, "tombstone-commit"))
+    return OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT;
+  else if (!strcmp (str, "commitmeta"))
+    return OSTREE_OBJECT_TYPE_COMMIT_META;
   g_assert_not_reached ();
   return 0;
 }
@@ -1414,7 +1420,13 @@ _ostree_loose_path (char              *buf,
                     OstreeObjectType   objtype,
                     OstreeRepoMode     mode)
 {
-  _ostree_loose_path_with_suffix (buf, checksum, objtype, mode, "");
+  *buf = checksum[0];
+  buf++;
+  *buf = checksum[1];
+  buf++;
+  snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s",
+            checksum + 2, ostree_object_type_to_string (objtype),
+            (!OSTREE_OBJECT_TYPE_IS_META (objtype) && mode == OSTREE_REPO_MODE_ARCHIVE_Z2) ? "z" : "");
 }
 
 /**
@@ -1442,33 +1454,6 @@ _ostree_header_gfile_info_new (mode_t mode, uid_t uid, gid_t gid)
   return ret;
 }
 
-/*
- * _ostree_loose_path_with_suffix:
- * @buf: Output buffer, must be _OSTREE_LOOSE_PATH_MAX in size
- * @checksum: ASCII checksum
- * @objtype: Object type
- * @mode: Repository mode
- *
- * Like _ostree_loose_path, but also append a further arbitrary
- * suffix; useful for finding non-core objects.
- */
-void
-_ostree_loose_path_with_suffix (char              *buf,
-                                const char        *checksum,
-                                OstreeObjectType   objtype,
-                                OstreeRepoMode     mode,
-                                const char        *suffix)
-{
-  *buf = checksum[0];
-  buf++;
-  *buf = checksum[1];
-  buf++;
-  snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s%s",
-            checksum + 2, ostree_object_type_to_string (objtype),
-            (!OSTREE_OBJECT_TYPE_IS_META (objtype) && mode == OSTREE_REPO_MODE_ARCHIVE_Z2) ? "z" : "",
-            suffix);
-}
-
 /*
  * _ostree_get_relative_object_path:
  * @checksum: ASCII checksum string
index b86756723e385ebdb1bb591f38803c21fdc4a313..415369d5484bf518d3056430fef0d1fcacfee4f7 100644 (file)
@@ -72,6 +72,7 @@ G_BEGIN_DECLS
  * @OSTREE_OBJECT_TYPE_DIR_META: Directory metadata
  * @OSTREE_OBJECT_TYPE_COMMIT: Toplevel object, refers to tree and dirmeta for root
  * @OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT: Toplevel object, refers to a deleted commit
+ * @OSTREE_OBJECT_TYPE_COMMIT_META: Detached metadata for a commit
  *
  * Enumeration for core object types; %OSTREE_OBJECT_TYPE_FILE is for
  * content, the other types are metadata.
@@ -82,6 +83,7 @@ typedef enum {
   OSTREE_OBJECT_TYPE_DIR_META = 3,            /* .dirmeta */
   OSTREE_OBJECT_TYPE_COMMIT = 4,              /* .commit */
   OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT = 5,    /* .commit-tombstone */
+  OSTREE_OBJECT_TYPE_COMMIT_META = 6,         /* .commitmeta */
 } OstreeObjectType;
 
 /**
@@ -90,14 +92,14 @@ typedef enum {
  *
  * Returns: %TRUE if object type is metadata
  */
-#define OSTREE_OBJECT_TYPE_IS_META(t) (t >= 2 && t <= 5)
+#define OSTREE_OBJECT_TYPE_IS_META(t) (t >= 2 && t <= 6)
 
 /**
  * OSTREE_OBJECT_TYPE_LAST:
  *
  * Last valid object type; use this to validate ranges.
  */
-#define OSTREE_OBJECT_TYPE_LAST OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT
+#define OSTREE_OBJECT_TYPE_LAST OSTREE_OBJECT_TYPE_COMMIT_META
 
 /**
  * OSTREE_DIRMETA_GVARIANT_FORMAT:
index 3670dea7074684af585cfb9a63277587f19a4ae8..662ee21e7e959f92422ab7766ee908b11d135af1 100644 (file)
@@ -2058,8 +2058,7 @@ _ostree_repo_get_commit_metadata_loose_path (OstreeRepo        *self,
                                              const char        *checksum)
 {
   char buf[_OSTREE_LOOSE_PATH_MAX];
-  _ostree_loose_path_with_suffix (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT, self->mode,
-                                  "meta");
+  _ostree_loose_path (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode);
   return g_file_resolve_relative_path (self->objects_dir, buf);
 }
 
index 672da831d7c39167e3548a0b3b59218061290b69..b4a565e3d1796a541ada472ff38694d10619cd58 100644 (file)
@@ -1316,8 +1316,7 @@ enqueue_one_object_request (OtPullData        *pull_data,
   if (is_detached_meta)
     {
       char buf[_OSTREE_LOOSE_PATH_MAX];
-      _ostree_loose_path_with_suffix (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT,
-                                      pull_data->remote_mode, "meta");
+      _ostree_loose_path (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, pull_data->remote_mode);
       obj_uri = suburi_new (pull_data->base_uri, "objects", buf, NULL);
     }
   else
index c6520a804c875e2fbe20c478a5e3e1bd8e317f1f..e30b48cf89dd4c7ea5cea6d4e39571132259a3a8 100644 (file)
@@ -3120,8 +3120,7 @@ ostree_repo_delete_object (OstreeRepo           *self,
     {
       char meta_loose[_OSTREE_LOOSE_PATH_MAX];
 
-      _ostree_loose_path_with_suffix (meta_loose, sha256,
-                                      OSTREE_OBJECT_TYPE_COMMIT, self->mode, "meta");
+      _ostree_loose_path (meta_loose, sha256, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode);
 
       do
         res = unlinkat (self->objects_dir_fd, meta_loose, 0);